package com.qf.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.feign.CityFeign;
import com.qf.entity.City;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/system/city")
@Slf4j
public class SystemCityController {

    @Autowired
    private CityFeign cityFeign;

    /**
     * 获得城市列表
     * @return
     */
    @RequestMapping("/list")
    public String cityList(Integer cpage, Model model){

        //获得城市列表信息 - 通过Feign调用城市服务
        Page<City> page = cityFeign.cityList(cpage).getData();
        model.addAttribute("page", page);

        return "citylist";
    }

    /**
     * 新增城市
     * @return
     */
    @RequestMapping("/insert")
    public String cityInsert(City city){
        log.info("[cityinsert] 新增城市！参数为：" + city);
        //保存城市信息 - Feign调用城市服务
        cityFeign.cityInsert(city);
        return "redirect:/system/city/list";
    }
}
